home *** CD-ROM | disk | FTP | other *** search
- /*
- * Copyright (C) 1994, Silicon Graphics, Inc.
- * All Rights Reserved.
- *
- * This is UNPUBLISHED PROPRIETARY SOURCE CODE of Silicon Graphics, Inc.;
- * the contents of this file may not be disclosed to third parties, copied or
- * duplicated in any form, in whole or in part, without the prior written
- * permission of Silicon Graphics, Inc.
- *
- * RESTRICTED RIGHTS LEGEND:
- * Use, duplication or disclosure by the Government is subject to restrictions
- * as set forth in subdivision (c)(1)(ii) of the Rights in Technical Data
- * and Computer Software clause at DFARS 252.227-7013, and/or in similar or
- * successor clauses in the FAR, DOD or NASA FAR Supplement. Unpublished -
- * rights reserved under the Copyright Laws of the United States.
- */
- #include <malloc.h>
- #include <assert.h>
- #include <string.h>
- main(argc, argv)
- int argc;
- char **argv;
- {
- extern int malloc_stacktrace_get_depth;
- int i;
- char *p;
- void *ptr1, *ptr2, *ptr3, *ptr4;
-
-
- malloc_stacktrace_get_depth = -1;
-
-
- malloc_reset();
-
- for (i = 0; i < 5; ++i)
- p = malloc(i); /* 4 out of 5 leaks */
- free(p);
- free(realloc(realloc(malloc(5), 200), 1));
-
- if (argv[1]) {
- if (!fopen(argv[1], "r")) /* open the file and never close it */
- perror(argv[1]);
- }
-
-
- ptr1 = malloc(5);
- ptr2 = malloc(10); /* should show up as a leak */
- ptr3 = malloc(15); /* should show up as a leak */
-
- ptr2 = malloc(20);
-
- free(ptr1);
- free(ptr2);
-
- ptr4 = malloc(200);
-
- free(strdup("heh heh. this sucks. heh heh heh."));
-
- malloc_info(5);
-
- free(ptr4);
- free(ptr4); /* freed twice -- debug malloc should complain*/
-
-
-
- printf("Ha!\n"); /* just to make sure we got here without dumping core */
- malloc_info(5);
- malloc_info_cleanup();
- malloc_info(1);
- malloc_info_cleanup();
- malloc_info(5);
- malloc_info_cleanup();
- malloc_info(1);
- malloc_info_cleanup();
- assert(malloc(1));
- malloc_info_cleanup(); /* makes subsequent mallocs fail! */
- assert(malloc(1));
- }
-